#pragma once
#include <logs.hpp>
#include <sstream>

namespace usrtos {

class LogLevel {
private:
	int m_level;
	usrtlog *m_log;
public:
	LogLevel(){};

	LogLevel(logs& m, int l) : m_level(l) {
		std::stringstream ln;
		ln << "log" << l;
		m_log = m[ln.str()];
	};

	void operator()(const char * format, ...) {
		va_list args;
		if(m_log) {
			va_start (args, format);
			m_log->_printf(format, args);
			va_end (args);
		}
		else {
			std::cerr << "miss log " << m_level << std::endl;
		}
	};
	
	void put(std::string& s) {
		m_log->put(s);
	};

	void operator()() {
		m_log->dump();
	};
	struct logF {
		usrtlog *m;
		logF(usrtlog *l) {m = l;}
		void operator()(const char * format, ...) {
			va_list args;
			if(m) {
				va_start (args, format);
				m->_printf(format, args);
				va_end (args);
			}	
		};
	};
	logF&& operator[](int i) {
		if(m_log->m_ptrigger->test(i))
			return std::move(logF(m_log));
		else
			return std::move(logF(nullptr));
	};
	void init_trigger() { m_log->m_ptrigger->init();    };
	void care(int i)    { m_log->m_ptrigger->care(i);   };
	void uncare(int i)  { m_log->m_ptrigger->uncare(i); };
	void disable(int i) { m_log->m_ptrigger->disable(i);};
	void enable(int i)  { m_log->m_ptrigger->enable(i); };
	usrtlog *getLog() { return m_log; };
	
}; // class LogLevel

extern LogLevel				SYSLOG;
extern LogLevel				 DEBUG;
extern LogLevel				  INFO;
extern LogLevel				  WARN;
extern LogLevel				 ERROR;
extern LogLevel				 FATAL;

}; // namespace usrtos
